// pages/saleClass/index.js
import urls from '../../utils/urls.js'
import loginFn from '../../utils/login.js'
// const util=require('../../utils/util.js')
var app = getApp()
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		teacherId: '',
		list: [],
		page: 1,
		totalPage: null,
	},
	//活動項目點擊詳情
	infoclass: function(e) {
		let id = e.currentTarget.dataset.id
		wx.navigateTo({
			// url: '/pages/infoclass/infoclass?courseId=' + id,
			url: '/pages/classdetail/index?courseId=' + id,
		})
	},
	//课程
	courseList: function(options) {
		let that = this
		let page = this.data.page;
		let totalPage = this.data.page;
		if(page > 1 && page > totalPage) {
			return false;
		}
		let courseList = loginFn()
		courseList.teacherId = this.data.teacherId;
		courseList.page = page;
		wx.request({
			url: urls.teachercourseList,
			data: courseList,
			success: function(res) {
				if(res.data.code == '0') {
					let list = that.data.list;
					let resData = res.data.data;
					totalPage = resData.totalPage;
					page ++;
					list = list.concat(resData.list);
					that.setData({
						page: page,
						totalPage: totalPage,
						list: list
					})
				}

			}
		})
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		console.log('options:',options);
		this.setData({
			teacherId: options.teacherId
		});
		this.courseList();
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {
		this.courseList();
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
